home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / python2.5 / glob.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-29  |  2KB  |  89 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''Filename globbing utility.'''
  5. import os
  6. import fnmatch
  7. import re
  8. __all__ = [
  9.     'glob',
  10.     'iglob']
  11.  
  12. def glob(pathname):
  13.     '''Return a list of paths matching a pathname pattern.
  14.  
  15.     The pattern may contain simple shell-style wildcards a la fnmatch.
  16.  
  17.     '''
  18.     return list(iglob(pathname))
  19.  
  20.  
  21. def iglob(pathname):
  22.     '''Return a list of paths matching a pathname pattern.
  23.  
  24.     The pattern may contain simple shell-style wildcards a la fnmatch.
  25.  
  26.     '''
  27.     if not has_magic(pathname):
  28.         if os.path.lexists(pathname):
  29.             yield pathname
  30.         
  31.         return None
  32.     
  33.     (dirname, basename) = os.path.split(pathname)
  34.     if not dirname:
  35.         for name in glob1(os.curdir, basename):
  36.             yield name
  37.         
  38.         return None
  39.     
  40.     if has_magic(dirname):
  41.         dirs = iglob(dirname)
  42.     else:
  43.         dirs = [
  44.             dirname]
  45.     if has_magic(basename):
  46.         glob_in_dir = glob1
  47.     else:
  48.         glob_in_dir = glob0
  49.     for dirname in dirs:
  50.         for name in glob_in_dir(dirname, basename):
  51.             yield os.path.join(dirname, name)
  52.         
  53.     
  54.  
  55.  
  56. def glob1(dirname, pattern):
  57.     if not dirname:
  58.         dirname = os.curdir
  59.     
  60.     
  61.     try:
  62.         names = os.listdir(dirname)
  63.     except os.error:
  64.         return []
  65.  
  66.     if pattern[0] != '.':
  67.         names = filter((lambda x: x[0] != '.'), names)
  68.     
  69.     return fnmatch.filter(names, pattern)
  70.  
  71.  
  72. def glob0(dirname, basename):
  73.     if basename == '':
  74.         if os.path.isdir(dirname):
  75.             return [
  76.                 basename]
  77.         
  78.     elif os.path.lexists(os.path.join(dirname, basename)):
  79.         return [
  80.             basename]
  81.     
  82.     return []
  83.  
  84. magic_check = re.compile('[*?[]')
  85.  
  86. def has_magic(s):
  87.     return magic_check.search(s) is not None
  88.  
  89.